#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

namespace fastio{
    struct{template<typename T>operator T(){
        T x=0;char f=0,c=getchar();
        while(c<'0'||c>'9'){if(c=='-')f=1;c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+(c^48);c=getchar();}
        return f?-x:x;
    }}in;int stk[40],tp;
    template<typename T>void out(T x,char c=0){
        if(x<0)putchar('-'),x=-x;
        do stk[++tp]=x%10,x/=10;while(x);
        while(tp)putchar(stk[tp--]^48);
        if(c)putchar(c);
    }
}using fastio::in;using fastio::out;

const int dx[] = {1,-1,0,0};
const int dy[] = {0,0,-1,1};
const int N = 2005;
pair<int,int> fa[N][N];
bool vis[N][N];
char s[N][N];
int a[N][N];
int n,m,q;

void dfs(int x,int y){
    vis[x][y] = true;
    for(int k=0;k<4;k++){
        int tx = x+dx[k],ty = y+dy[k];
        if(tx<1||tx>n||ty<1||ty>m||s[tx][ty]!='1'||vis[tx][ty])
            continue;
        fa[tx][ty] = {x,y};
        dfs(tx,ty);
    }
}

int main(){
    freopen("unicom.in","r",stdin);
    freopen("unicom.out","w",stdout);
    n = in,m = in,q = in;
    for(int k=1;k<=n;k++)
        scanf("%s",s[k]+1);
    for(int k=1;k<=n;k++)
        for(int j=1;j<=m;j++)
            if(s[k][j]=='1'&&!vis[k][j]){
                fa[k][j] = {k,j};
                dfs(k,j);
                a[k][j]++;
            }
    for(int k=1;k<=n;k++)
        for(int j=1;j<=m;j++)
            a[k][j] += a[k][j-1];
    for(int k=1;k<=n;k++)
        for(int j=1;j<=m;j++)
            a[k][j] += a[k-1][j];
    while(q--){
        int x1 = in,y1 = in,x2 = in,y2 = in;
        int ans = a[x2][y2]-a[x1-1][y2]-a[x2][y1-1]+a[x1-1][y1-1];
        auto in = [&x1,&y1,&x2,&y2](pair<int,int> u){return u.first>=x1&&u.first<=x2&&u.second>=y1&&u.second<=y2;};
        if(x1==x2){
            for(int k=y1;k<=y2;k++)
                if(s[x1][k]=='1'&&!in(fa[x1][k]))
                    ans++;
        }
        else if(y1==y2){
            for(int k=x1;k<=x2;k++)
                if(s[k][y1]=='1'&&!in(fa[k][y1]))
                    ans++;
        }
        else{
            for(int k=x1;k<x2;k++)
                if(s[k][y1]=='1'&&!in(fa[k][y1]))
                    ans++;
            for(int k=y1;k<y2;k++)
                if(s[x2][k]=='1'&&!in(fa[x2][k]))
                    ans++;
            for(int k=x2;k>x1;k--)
                if(s[k][y2]=='1'&&!in(fa[k][y2]))
                    ans++;
            for(int k=y2;k>y1;k--)
                if(s[x1][k]=='1'&&!in(fa[x1][k]))
                    ans++;
        }
        out(ans,'\n');
    }
    return 0;
}